package agents.task;

import java.util.ArrayList;
import java.util.List;

import agents.Ant;
import agents.resource.ResourceAgent;
import domain.Segment;

public abstract class ExplorationAnt implements Ant {
	
	//mss dit door een factory laten doen
	static public ExplorationAnt createExplorationAnt(TaskAgent origin, Segment destination) {
		return new StartExplorationAnt(origin,destination);
	}
	
	//maakt nieuwe exploration ant aan voor gegeven taskagent (nt voor gebruik door kloning)
	protected ExplorationAnt(TaskAgent origin, Segment destination) {
		this.setHopsLeft(MAX_EXPLORER_HOPS);
		this.origin = origin;
		this.currentResource = origin.getCurrentResource();
		this.destination = destination;
		this.trip = new Trip();
	}
	
	//copy constructor
	protected ExplorationAnt(ResourceAgent agent, ExplorationAnt ant) {
		this.destination = ant.getDestination();
		this.currentResource = agent;
		this.origin = ant.getOrigin();
		this.setTrip(ant.getTrip());
		setHopsLeft(ant.getHopsLeft());
	}
	
	//verwerkt informatie van huidige resource en springt naar buren downstream (door kloning)
	//vermindert hopsLeft; wanneer hopsLeft == 0 of bestemming bereikt, "keer terug" en verwittigt taskagent
	public abstract void doStep();

	/* kindertjes van de mier */
	public List<Ant> getChildAnts() {
		return childAnts;
	}
	protected void setChildAnts(List<Ant> lst) {
		this.childAnts = lst;
	}
	private List<Ant> childAnts = new ArrayList<Ant>();

	/* terminatie */
	public boolean isTerminated() {
		return isTerminated;
	}
	protected void terminate() {
		isTerminated = true;
	}
	private boolean isTerminated = false;
	
	/* locatie (=resource agent) van ant */
	protected ResourceAgent getCurrentResource() {
		return currentResource;
	}
	private final ResourceAgent currentResource;
	
	private final int MAX_EXPLORER_HOPS = 5;

	/* origin (=task agent) */
	protected TaskAgent getOrigin() {
		return origin;
	}
	private final TaskAgent origin;
	
	/* destination segment */
	protected Segment getDestination() {
		return destination;
	}
	private final Segment destination;
	
	/* hops left */
	protected void setHopsLeft(int hopsLeft) {
		this.hopsLeft = hopsLeft;
	}
	protected int getHopsLeft() {
		return hopsLeft;
	}
	private int hopsLeft;
	
	/* trip tot dusver verkend*/
	public Trip getTrip() {
		return trip;
	}
	protected void setTrip(Trip t) {
		this.trip = t;
	}
	private Trip trip;
	
	@Override
	public String toString() {
		return "location: "+getCurrentResource().toString()+", origin: " + getOrigin().toString();
	}

}
